Skip to content

fix: add content-type check for non-JSON responses in HttpClient#826

Merged
Avijit-Microsoft merged 2 commits into
devfrom
pk-40958-user-fetch-html-error
Apr 23, 2026
Merged

fix: add content-type check for non-JSON responses in HttpClient#826
Avijit-Microsoft merged 2 commits into
devfrom
pk-40958-user-fetch-html-error

Conversation

@Pavan-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

This pull request adds an extra validation step to the HttpClient utility to ensure that all HTTP responses are in JSON format before attempting to parse them. This helps prevent runtime errors when the server returns unexpected content types.

Error handling improvements:

  • Added a check in HttpClient (src/App/src/utils/httpClient.ts) to verify that the response's Content-Type header includes application/json, throwing an error if a non-JSON response is received.

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

Co-authored-by: Copilot <copilot@github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a defensive Content-Type validation to avoid attempting response.json() on non-JSON responses, improving runtime safety when calling external endpoints.

Changes:

  • Added a Content-Type header check in HttpClient.fetchExternal() to ensure responses are JSON before parsing.
  • Throws a clearer early error when a non-JSON response is received.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/App/src/utils/httpClient.ts
Comment thread src/App/src/utils/httpClient.ts
Comment thread src/App/src/utils/httpClient.ts Outdated
@Avijit-Microsoft
Avijit-Microsoft merged commit 5125900 into dev Apr 23, 2026
4 checks passed
@Pavan-Microsoft
Pavan-Microsoft deleted the pk-40958-user-fetch-html-error branch April 27, 2026 17:03
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.4.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants